package com.xbongbong.paas.util;

import com.xbongbong.paas.field.FieldAttrEntity;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 吴峰
 * @date 2022/08/05 16:13
 */
public class ExcelLogUtil {


    /**
     * 部分导出日志处理
     * @param logMemo
     * @param partialSelectAttrsList
     */
    public static String excelPartialExportLog(String logMemo, Map<String, FieldAttrEntity> explainMap, List<String> partialSelectAttrsList){
        //获取选择字段中的attrName
        Map<String,String> partialSelectAttrsMap = new HashMap<>();
        partialSelectAttrsList.forEach(item->{
            if (!explainMap.containsKey(item)) {
                return;
            }
            partialSelectAttrsMap.put(item,explainMap.get(item).getAttrName());
        });
        logMemo = StringUtils.isEmpty(logMemo) ? "" : logMemo;
        int index = 0;
        for (String logMemoStr : partialSelectAttrsMap.keySet()){
            if (index > 3){
                logMemo = "导出字段： " + logMemo.substring(0,logMemo.length()-1) + "等，共计" + partialSelectAttrsMap.size() +"个字段";
                break;
            }
            logMemo += partialSelectAttrsMap.get(logMemoStr) + ",";
            index ++;
        }
        if (index <=3 && index>0){
            logMemo = "导出字段： " + logMemo.substring(0,logMemo.length()-1) + "，共计" +  partialSelectAttrsMap.size() +"个字段";
        }
        return logMemo;
    }
}
